<template>
  <div>
    <a-card class="card-header">
      <a-form-model :model="queryParam">
        <a-row :gutter="24">
          <a-col :span="5">
            <a-form-model-item
              label="商品名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                v-model.trim="queryParam.goodsName"
                placeholder="请输入商品名称"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="5">
            <a-form-model-item
              label="商品编号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                v-model.trim="queryParam.goodsCode"
                placeholder="请输入商品编号"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="2">
            <a-button
              type="primary"
              style="margin-top:3px"
              @click="handleSearch"
              >查询</a-button
            >
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <!-- 表格区域 -->
    <a-card class="card-content">
      <br />
      <a-table
        :columns="columns"
        :data-source="tableData"
        :loading="loading"
        :pagination="pagination"
        @change="handleTableChange"
        :rowKey="(record, index) => record.id"
        bordered
      >
        <template slot="shelfName" slot-scope="text">
          <div style="text-align:left" v-if="text.length > 0">
            <div v-for="(item, index) in text" :key="index">
              {{ item }}
            </div>
          </div>
          <div v-else style="color:#c7254e">
            无库存
          </div>
        </template>
      </a-table>
    </a-card>
  </div>
</template>

<script>
import { columns } from "./components/tableConfig";
import { tableMinxins } from "@/unit/mixins/tableMinxins.js";
import api from "@/api/apiServer";

export default {
  components: {},
  mixins: [tableMinxins],
  data() {
    return {
      columns,
      option: [], // 仓库管理数据源
    };
  },
  activated() {
    this.queryParam = {};
    this.pagination.current = 1;
    this.pagination.pageNumber = 1;
    this.getList();
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 获取列表数据
    async getList(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      this.loading = true;
      if (arg === 1) {
        this.pagination.current = 1;
      }
      var params = this.getQueryParams();
      const res = await api.instockFindInstockGoods(params);
      this.tableData = res.data.data;
      this.tableData.forEach((element) => {
        element.shelfName = element.shelfName.split(","); //逗号切割并换行
      });
      this.pagination.total = res.data.total;
      this.loading = false;
    },
  },
};
</script>

<style lang="less" scoped>
.card-header {
  margin: 20px 0;
}
.card-content {
  button {
    margin-right: 20px;
  }
}
::v-deep .ant-tree-node-content-wrapper {
  width: 90%;
}
::v-deep .ant-form-item {
  margin-bottom: 0;
}
</style>
